package com.wc.算法提高课.B第二章_搜索.IDAStar.回转游戏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/30 17:40
 * @description https://www.acwing.com/problem/content/183/
 */
public class Main {

    //        打表
    //         A     B
    //         0     1
    //         2     3
    //G  4  5  6  7  8  9 10 C
    //        11    12
    //H 13 14 15 16 17 18 19 D
    //        20    21
    //        22    23
    //         F     G

    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 24;
    static int[][] op = {
            {0, 2, 6, 11, 15, 20, 22},
            {1, 3, 8, 12, 17, 21, 23},
            {10, 9, 8, 7, 6, 5, 4},
            {19, 18, 17, 16, 15, 14, 13},
            {23, 21, 17, 12, 8, 3, 1},
            {22, 20, 15, 11, 6, 2, 0},
            {13, 14, 15, 16, 17, 18, 19},
            {4, 5, 6, 7, 8, 9, 10},
    };
    // 操作的反方向
    static int[] opposite = {5, 4, 7, 6, 1, 0, 3, 2};
    // 中间元素坐标
    static int[] center = {6, 7, 8, 11, 12, 15, 16, 17};
    static int[] q = new int[N];
    // 存路径
    static int[] path = new int[100];
    static int n;

    public static void main(String[] args) {
        while ((q[0] = sc.nextInt()) != 0) {
            for (int i = 1; i < N; i++) {
                q[i] = sc.nextInt();
            }
            int depth = 0;
            while (!dfs(0, depth, -1)) depth++;
            if (depth == 0) out.println("No moves needed");
            else {
                for (int i = 0; i < depth; i++) {
                    out.print((char) (path[i] + 'A'));
                }
                out.println();
            }
            out.println(q[6]);
        }
        out.flush();
    }

    static boolean dfs(int u, int maxDepth, int last) {
        if (u + f() > maxDepth) return false;
        if (f() == 0) return true;

        for (int i = 0; i < 8; i++) {
            if (opposite[i] != last) {
                operator(i);
                path[u] = i;
                if (dfs(u + 1, maxDepth, i)) return true;
                operator(opposite[i]);
            }
        }
        return false;
    }

    static int f() {
        int[] sum = new int[4];
        for (int i = 0; i < 8; i++) {
            sum[q[center[i]]]++;
        }
        int maxv = 0;
        for (int i = 1; i < 4; i++) maxv = Math.max(sum[i], maxv);
        return 8 - maxv;
    }

    static void operator(int x) {
        int t = q[op[x][0]];
        for (int i = 0; i < 6; i++) q[op[x][i]] = q[op[x][i + 1]];
        q[op[x][6]] = t;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
